package com.biconn.bigdata.jstrom.mongo;

import java.util.Date;

import org.bson.Document;
import org.bson.types.ObjectId;

public class RequestData {
	/**
	 * Mongodb主键  id类型不可改
	 */
	
	private ObjectId id;
	
	private String cardNo;
	
	private Date createDate;
	
	private Date updateDate;
	
	//数据默认存储在位
	private String jsonData;
	//转换为toDocument 在新增和修改时都需要转换  新增和修改的对象都是Document
	
	public Document toDocument(RequestData requestData){
		Document document =  new Document();
		document.put("cardNo", requestData.getCardNo());
		document.put("createDate", requestData.getCreateDate());
		document.put("updateDate", requestData.getUpdateDate());
		document.put("jsonData", requestData.getJsonData());
		return document;
	}
	
	//转换为实体bean  查询结果为Document  若想用该bean则需要转换
	public void toRequestData(Document document){
		this.setId(document.getObjectId("_id"));
		this.setCardNo(document.getString("cardNo"));
		this.setCreateDate(document.getDate("createDate"));
		this.setUpdateDate(document.getDate("updateDate"));
		this.setJsonData(document.getString("jsonData"));
	}
 
	/**
	 * @return the id
	 */
	public ObjectId getId() {
		return id;
	}
 
	/**
	 * @param id the id to set
	 */
	public void setId(ObjectId id) {
		this.id = id;
	}
 
	/**
	 * @return the cardNo
	 */
	public String getCardNo() {
		return cardNo;
	}
 
	/**
	 * @param cardNo the cardNo to set
	 */
	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}
 
 
	/**
	 * @return the createDate
	 */
	public Date getCreateDate() {
		return createDate;
	}
 
	/**
	 * @param firstDate the firstDate to set
	 */
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	public String getJsonData() {
		return jsonData;
	}
	public void setJsonData(String jsonData) {
		this.jsonData = jsonData;
	}

	public Date getUpdateDate() {
		return updateDate;
	}
	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}
}
